#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>

int main()
{

  printf("before fork : I am a process ,pid: %d ,ppid: %d\n ",getpid(),getppid());

  sleep(5);
  printf("开始创建进程啦!\n");
  sleep(1);

  pid_t id = fork();
  if(id < 0)
    return 1;
  else if (id == 0)
  {
    //son 
    while(1)
    {
      printf("after fork ,我子进程: I am a process ,pid %d,ppid %d,id : %d\n",getpid(),getppid(),id);
      sleep(1);

    }
  }
  else 
  {

    while(1)
    {
      printf("after fork ,我是父进程 I am a process ,pid: %d,ppid:%d return id : %d\n",getpid(),getppid(),id);
    sleep(1);
    }
  }

  sleep(2);
  return 0;
}
